home *** CD-ROM | disk | FTP | other *** search
- Path: library.erc.clarkson.edu!rpi!not-for-mail
- From: "john (j.d.) hickin" <hickin@bnr.ca>
- Newsgroups: comp.lang.c++,comp.lang.c++.moderated
- Subject: Re: Argc & Argv
- Date: 28 Feb 1996 15:01:46 -0000
- Organization: Nortel Technology
- Sender: cppmods@netlab.cs.rpi.edu
- Approved: Dietmar.Kuehl@uni-konstanz.de
- Message-ID: <4h1qoq$8kh@netlab.cs.rpi.edu>
- References: <4gta9f$df5@netlab.cs.rpi.edu>
- NNTP-Posting-Host: netlab.cs.rpi.edu
- X-Original-Date: Tue, 27 Feb 1996 14:19:57 -0500
-
- Rick Richert wrote:
- >
- > >> I tried posting this last week and am not sure if it was posted or
- > >> not. Soooo, I'm trying again.
- >
- > I have some global objects defined outside the main routine and I would
- > like to pass the argc and argv values to their constructors. For example,
- >
- >
- > SomeClass obj( argc, argv);
- >
- > int main( int argc, char **argv) {
- >
- > blah, blah, blah
- >
- > }
- >
- > Unfortunately, the compiler tells me that argc and argv are not defined
- > or else not available for obj.
- >
- > Currently, I get around this problem by creating the global obj and then
- > inside of main, I initialize obj via a method that takes argc and argv.
- >
- > I would prefer to pass the arg vars to the constructor. Does anyone know
- > how I can pass the arg vars without being inside of main?
- >
- > [ Articles to moderate: mailto:c++-submit@netlab.cs.rpi.edu ]
- > [ Read the C++ FAQ: http://www.connobj.com/cpp/cppfaq.htm ]
- > [ Moderation policy: http://www.connobj.com/cpp/guide.htm ]
- > [ Comments? mailto:c++-request@netlab.cs.rpi.edu ]
-
- Some systems let you get at argc/argv before main() but portable code
- can't use
- that approach.
-
- An alternative to consider is the use of a data file to specify your
- arguments
- in. Put the data file's path name in a known environment variable.
- Make the
- data file format exactly the same as your command line format. Then you
- can
- specify 'pre-main' args independently of 'main-args', etc. This
- approach is
- especially useful for controlling trace objects dynamically.
-
- --
- John Hickin Nortel Technology, Montreal, Quebec
- (514) 765-7924 hickin@bnr.ca
-
- [ Articles to moderate: mailto:c++-submit@netlab.cs.rpi.edu ]
- [ Read the C++ FAQ: http://www.connobj.com/cpp/cppfaq.htm ]
- [ Moderation policy: http://www.connobj.com/cpp/guide.htm ]
- [ Comments? mailto:c++-request@netlab.cs.rpi.edu ]
-